package com.ruoyi.project.surveys.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.surveys.domain.SurveysInfoType;
import com.ruoyi.project.surveys.service.ISurveysInfoTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 问卷类型Controller
 * 
 * @author zhimin-hu
 * @date 2020-05-02
 */
@RestController
@RequestMapping("/surveys/type")
public class SurveysInfoTypeController extends BaseController
{
    @Autowired
    private ISurveysInfoTypeService surveysInfoTypeService;

    /**
     * 查询问卷类型列表
     */
    @PreAuthorize("@ss.hasPermi('surveys:type:list')")
    @GetMapping("/list")
    public AjaxResult list(SurveysInfoType surveysInfoType)
    {
        List<SurveysInfoType> list = surveysInfoTypeService.selectSurveysInfoTypeList(surveysInfoType);
        return AjaxResult.success(list);
    }

    /**
     * 导出问卷类型列表
     */
    @PreAuthorize("@ss.hasPermi('surveys:type:export')")
    @Log(title = "问卷类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SurveysInfoType surveysInfoType)
    {
        List<SurveysInfoType> list = surveysInfoTypeService.selectSurveysInfoTypeList(surveysInfoType);
        ExcelUtil<SurveysInfoType> util = new ExcelUtil<SurveysInfoType>(SurveysInfoType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 获取问卷类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('surveys:type:query')")
    @GetMapping(value = "/{infoTypeId}")
    public AjaxResult getInfo(@PathVariable("infoTypeId") Long infoTypeId)
    {
        return AjaxResult.success(surveysInfoTypeService.selectSurveysInfoTypeById(infoTypeId));
    }

    /**
     * 新增问卷类型
     */
    @PreAuthorize("@ss.hasPermi('surveys:type:add')")
    @Log(title = "问卷类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurveysInfoType surveysInfoType)
    {
        surveysInfoType.setCreateBy(SecurityUtils.getUsername());
        return toAjax(surveysInfoTypeService.insertSurveysInfoType(surveysInfoType));
    }

    /**
     * 修改问卷类型
     */
    @PreAuthorize("@ss.hasPermi('surveys:type:edit')")
    @Log(title = "问卷类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurveysInfoType surveysInfoType)
    {
        surveysInfoType.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(surveysInfoTypeService.updateSurveysInfoType(surveysInfoType));
    }

    /**
     * 删除问卷类型
     */
    @PreAuthorize("@ss.hasPermi('surveys:type:remove')")
    @Log(title = "问卷类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoTypeIds}")
    public AjaxResult remove(@PathVariable Long[] infoTypeIds)
    {
        return toAjax(surveysInfoTypeService.deleteSurveysInfoTypeByIds(infoTypeIds));
    }
}
